package com.mes.service.lc;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.functors.StringValueTransformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mes.dao.lc.ProductGokuMapper;
import com.mes.entity.lc.ProductGoku;
import com.mes.entity.lc.ProductStock;
import com.mes.entity.yzl.OutLib;
import com.mes.entity.yzlExtend.ExtendProContactOrder;

/**
 * 产品出库service接口 实现类
 * @ClassName:ProductGokuServiceImpl
 * @Description:
 * @Author LC
 * @Date 2018年1月31日下午4:12:18
 * @version 1.0
 */
@Service
public class ProductGokuServiceImpl implements ProductGokuService {

	@Autowired
	ProductGokuMapper	productGokuMapper;

	/**
	 * 分页查询
	 */
	@Override
	public List<ProductGoku> selectfypgk(ProductGoku productGoku) {
		return productGokuMapper.selectfypgk(productGoku);
	}

	/**
	 * 查询总数
	 */
	@Override
	public int selectfypgkcont(ProductGoku productGoku) {
		return productGokuMapper.selectfypgkcont(productGoku);
	}

	/**
	 * 查询所有的未出库的销售出库单
	 * @return
	 */
	@Override
	public List<OutLib> selectoutliball() {
		return productGokuMapper.selectoutliball();
	}


	/**
	 * 根据销售出库单id，然后给出对应的具体信息
	 * @param ids
	 * @return
	 */
	@Override
	public List<ExtendProContactOrder> selectPcoall(Long ids) {
		return productGokuMapper.selectPcoall(ids);
	}

	/**
	 * 开始出库
	 */
	@Override
	public int savepgk(ExtendProContactOrder pgk, String suprname,
			String number, String nowtime) {
		
		//产品出库表
		ProductGoku productGoku = new ProductGoku();
		//产品库存
		ProductStock productStock = new ProductStock();
	    
		//添加产品出库
		productGoku.setPid(pgk.getProductorId());//产品基础主键
		productGoku.setLpodd(number);//出库单号
		productGoku.setLpgotime(nowtime);//出库时间
		productGoku.setLpcustome(suprname);//客户
		productGoku.setLpcar(pgk.getProduct().getCartype());//车种
		productGoku.setLpnumb(pgk.getProduct().getNum());//品编
		productGoku.setLpname(pgk.getProduct().getName());//品名
		productGoku.setLppici(pgk.getBatch());//批次
		productGoku.setLpnum(String.valueOf(pgk.getOutQ()));//数量
		productGoku.setLpcode(pgk.getBarcode());//条形码 
		productGoku.setLppeop("管理员");//录入人
		
		//添加产品库存
	    productStock.setSsck("产品");//所属仓库
	    
	    Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("pgk", productGoku);
		paramMap.put("ps", productStock);
		
		return productGokuMapper.savepgk(paramMap);
	}

	/**
	 * 修改销售出库单状态
	 * @param ids
	 */
	@Override
	public void updateoutlib(Long ids) {
		productGokuMapper.updateoutlib(ids);
		
	}
	
}
